from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-18 14:02:23.062562
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 18, Mar, 2022
Time: 14:02:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.5618
Nobs: 598.000 HQIC: -48.9656
Log likelihood: 7170.96 FPE: 4.19486e-22
AIC: -49.2230 Det(Omega_mle): 3.61324e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349978 0.066811 5.238 0.000
L1.Burgenland 0.108455 0.040680 2.666 0.008
L1.Kärnten -0.110644 0.021273 -5.201 0.000
L1.Niederösterreich 0.192845 0.085058 2.267 0.023
L1.Oberösterreich 0.122710 0.083891 1.463 0.144
L1.Salzburg 0.258628 0.043151 5.994 0.000
L1.Steiermark 0.036259 0.056959 0.637 0.524
L1.Tirol 0.102108 0.045985 2.220 0.026
L1.Vorarlberg -0.068180 0.040581 -1.680 0.093
L1.Wien 0.015134 0.074637 0.203 0.839
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054783 0.143635 0.381 0.703
L1.Burgenland -0.037848 0.087457 -0.433 0.665
L1.Kärnten 0.041989 0.045734 0.918 0.359
L1.Niederösterreich -0.204309 0.182863 -1.117 0.264
L1.Oberösterreich 0.455339 0.180355 2.525 0.012
L1.Salzburg 0.283056 0.092769 3.051 0.002
L1.Steiermark 0.112838 0.122454 0.921 0.357
L1.Tirol 0.305767 0.098861 3.093 0.002
L1.Vorarlberg 0.026457 0.087243 0.303 0.762
L1.Wien -0.029114 0.160459 -0.181 0.856
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198950 0.034174 5.822 0.000
L1.Burgenland 0.089541 0.020808 4.303 0.000
L1.Kärnten -0.007160 0.010881 -0.658 0.511
L1.Niederösterreich 0.241178 0.043507 5.543 0.000
L1.Oberösterreich 0.160122 0.042910 3.732 0.000
L1.Salzburg 0.039926 0.022072 1.809 0.070
L1.Steiermark 0.027160 0.029134 0.932 0.351
L1.Tirol 0.081671 0.023521 3.472 0.001
L1.Vorarlberg 0.054140 0.020757 2.608 0.009
L1.Wien 0.116641 0.038177 3.055 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118922 0.034142 3.483 0.000
L1.Burgenland 0.043577 0.020789 2.096 0.036
L1.Kärnten -0.012990 0.010871 -1.195 0.232
L1.Niederösterreich 0.171632 0.043467 3.949 0.000
L1.Oberösterreich 0.336392 0.042871 7.847 0.000
L1.Salzburg 0.099526 0.022052 4.513 0.000
L1.Steiermark 0.111742 0.029108 3.839 0.000
L1.Tirol 0.089371 0.023500 3.803 0.000
L1.Vorarlberg 0.060449 0.020738 2.915 0.004
L1.Wien -0.018848 0.038142 -0.494 0.621
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127170 0.064088 1.984 0.047
L1.Burgenland -0.044643 0.039023 -1.144 0.253
L1.Kärnten -0.045315 0.020406 -2.221 0.026
L1.Niederösterreich 0.135622 0.081592 1.662 0.096
L1.Oberösterreich 0.160490 0.080472 1.994 0.046
L1.Salzburg 0.284760 0.041393 6.879 0.000
L1.Steiermark 0.058319 0.054638 1.067 0.286
L1.Tirol 0.158155 0.044111 3.585 0.000
L1.Vorarlberg 0.097369 0.038927 2.501 0.012
L1.Wien 0.071184 0.071595 0.994 0.320
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077441 0.050007 1.549 0.121
L1.Burgenland 0.026143 0.030449 0.859 0.391
L1.Kärnten 0.053284 0.015923 3.346 0.001
L1.Niederösterreich 0.189925 0.063665 2.983 0.003
L1.Oberösterreich 0.331091 0.062792 5.273 0.000
L1.Salzburg 0.034797 0.032298 1.077 0.281
L1.Steiermark 0.008252 0.042633 0.194 0.847
L1.Tirol 0.118922 0.034419 3.455 0.001
L1.Vorarlberg 0.065714 0.030374 2.163 0.031
L1.Wien 0.096491 0.055865 1.727 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175470 0.060320 2.909 0.004
L1.Burgenland 0.005591 0.036728 0.152 0.879
L1.Kärnten -0.065859 0.019206 -3.429 0.001
L1.Niederösterreich -0.108527 0.076794 -1.413 0.158
L1.Oberösterreich 0.206624 0.075740 2.728 0.006
L1.Salzburg 0.054855 0.038959 1.408 0.159
L1.Steiermark 0.247245 0.051425 4.808 0.000
L1.Tirol 0.501167 0.041517 12.071 0.000
L1.Vorarlberg 0.064151 0.036638 1.751 0.080
L1.Wien -0.077734 0.067385 -1.154 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161839 0.066913 2.419 0.016
L1.Burgenland -0.001424 0.040742 -0.035 0.972
L1.Kärnten 0.062936 0.021305 2.954 0.003
L1.Niederösterreich 0.166149 0.085187 1.950 0.051
L1.Oberösterreich -0.056340 0.084019 -0.671 0.503
L1.Salzburg 0.208509 0.043217 4.825 0.000
L1.Steiermark 0.138998 0.057045 2.437 0.015
L1.Tirol 0.055883 0.046055 1.213 0.225
L1.Vorarlberg 0.146815 0.040643 3.612 0.000
L1.Wien 0.119839 0.074750 1.603 0.109
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390028 0.039385 9.903 0.000
L1.Burgenland -0.003277 0.023981 -0.137 0.891
L1.Kärnten -0.020892 0.012540 -1.666 0.096
L1.Niederösterreich 0.202637 0.050142 4.041 0.000
L1.Oberösterreich 0.229705 0.049454 4.645 0.000
L1.Salzburg 0.036545 0.025438 1.437 0.151
L1.Steiermark -0.015615 0.033577 -0.465 0.642
L1.Tirol 0.089278 0.027108 3.293 0.001
L1.Vorarlberg 0.051005 0.023922 2.132 0.033
L1.Wien 0.043569 0.043998 0.990 0.322
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036612 0.104178 0.167571 0.137817 0.096833 0.080395 0.032533 0.208893
Kärnten 0.036612 1.000000 -0.026997 0.131207 0.048705 0.084738 0.443671 -0.067044 0.089351
Niederösterreich 0.104178 -0.026997 1.000000 0.313544 0.119466 0.272284 0.066816 0.153299 0.292526
Oberösterreich 0.167571 0.131207 0.313544 1.000000 0.212696 0.294988 0.166935 0.137307 0.238916
Salzburg 0.137817 0.048705 0.119466 0.212696 1.000000 0.122626 0.091765 0.105102 0.124122
Steiermark 0.096833 0.084738 0.272284 0.294988 0.122626 1.000000 0.133593 0.106736 0.035426
Tirol 0.080395 0.443671 0.066816 0.166935 0.091765 0.133593 1.000000 0.063903 0.150929
Vorarlberg 0.032533 -0.067044 0.153299 0.137307 0.105102 0.106736 0.063903 1.000000 -0.003680
Wien 0.208893 0.089351 0.292526 0.238916 0.124122 0.035426 0.150929 -0.003680 1.000000